package com.joker.userExam.utils;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 李杰
 * @date 2021/3/23 - 21:49
 */
@Data
public class ResultUtil {

    //成功状态码
    public static final int OK = 1;
    //失败状态码
    public static final int ERROR = 0;

    //返回码
    private Integer code;
    //返回消息
    private String message;

    //存放数据
    private Object data;
    //其他数据
    private Map<String, Object> other = new HashMap<>();


    public ResultUtil(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResultUtil(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 快捷成功BaseResult对象
     *
     * @param message
     * @return
     */
    public static ResultUtil ok(String message) {
        return new ResultUtil(ResultUtil.OK, message);
    }

    public static ResultUtil ok(String message, Object data) {
        return new ResultUtil(ResultUtil.OK, message, data);
    }

    /**
     * 快捷失败BaseResult对象
     *
     * @param message
     * @return
     */
    public static ResultUtil error(String message) {
        return new ResultUtil(ResultUtil.ERROR, message);
    }

    /**
     * 自定义数据区域
     *
     * @param key
     * @param msg
     * @return
     */
    public ResultUtil append(String key, Object msg) {
        other.put(key, msg);
        return this;
    }

}
